from SCBAutoLibrary.base.basekeywords import SCBBaseKeywords

class _LoginKeywords(SCBBaseKeywords):
    """ Runs assertions against the content of the page.
    Returns booleans instead of throwing errors
    """
    def _initElementByVar(self):
        self.username = self._getVariableValue('${username}')
        self.password = self._getVariableValue('${password}')
        self.loginButton = self._getVariableValue('${loginButton}')

    def fill_login_field(self, username, password):
        self._initElementByVar()
        self.selenium2lib.wait_until_page_contains_element(self.username)
        self.selenium2lib.input_text(self.username, username)
        self.selenium2lib.input_password(self.password, password)

    def do_login_action(self):
        self._initElementByVar()
        self.selenium2lib.click_element(self.loginButton)

    def login_to_breeze(self, username, password):
        try:
            self._initElementByVar()
            self.fill_login_field(username, password)
            self.do_login_action()
        except AssertionError:
          	return False
